package com.common.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.common.constant.BalzLogger;

public class JDBCConnection {
	
	BalzLogger logger = new BalzLogger();

	public ResultSet queryBySql(String sql) {

		String connectionURL = "jdbc:mysql://localhost:3306/petshop";
		String driver = "com.mysql.jdbc.Driver";
		String username = "root";
		String password = "root";
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;

		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(connectionURL, username,	password);
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			
		} catch (ClassNotFoundException e) {
			logger.debug("Driver Error");
		} catch (SQLException e) {
			logger.debug("SQLException: " + e.getMessage());
		}

		return rs;

	}
	
	public Statement getStatement() {
		
		String connectionURL = "jdbc:mysql://localhost:3306/petshop";
		String driver = "com.mysql.jdbc.Driver";
		String username = "root";
		String password = "root";
		Connection conn = null;
		Statement stmt = null;
		
		try {
			Class.forName(driver);
			conn = DriverManager.getConnection(connectionURL, username,	password);
			stmt = conn.createStatement();
			
		} catch (ClassNotFoundException e) {
			logger.debug("Driver Error");
		} catch (SQLException e) {
			logger.debug("SQLException: " + e.getMessage());
		}
		
		return stmt;
		
	}

}
